window.onload = function (){

    initSiderbar();


}


/**
 *   1. 初始化 外层 li -- 城市信息
 *   2. 构建内层 ul，然后追加到对应的li上
 *   3. 为外层li添加点击事件
 *       点击时，实现内层 ul的显示-隐藏 切换
 *
 *       过度设计 ！！！
 * */
function initSiderbar(){

       var nav = document.getElementById('nav');
       for (var i in cities){
            var listItem = document.createElement('li');
            var currentCity= cities[i];
            var schools = currentCity.schools;
            listItem.innerText = currentCity.name;

           var innerUList = document.createElement('ul');
           for (var inner in schools){
                var innerListItem = document.createElement('li');
                innerListItem.innerText = schools[inner].name;
               innerUList.append(innerListItem);
           }
           listItem.append(innerUList);

           listItem.onclick =function (){

               if(this.children[0].style.display!='none'){
                   this.children[0].style.display = 'none';
               }else{
                   this.children[0].style.display = 'block';
               }
           }

            nav.append(listItem);
       }
}